package com.wangdong.mijiqiqi.builder.dialogtest;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * 作者：wangdong on 2018/8/31 19:41
 * 邮箱：2100520956@qq.com
 */

public class MyDialog extends Dialog {

    private String title;

    private int iconId;

    private Context context;

    public MyDialog(@NonNull Context context) {
        super(context);
    }

    public MyDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected MyDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public String getTitle() {
        return title;
    }

    public int getIconId() {
        return iconId;
    }


    public static class Builder {
        //设置默认值
        private String title = "Title";
        private int iconId = 0;
        private Context context;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder setTitle(String title) {
            this.title = title;
            return this;
        }

        public Builder setIconId(int iconId) {
            this.iconId = iconId;
            return this;
        }

        //应用我们的设置
        private void applyConfig(MyDialog myDialog) {
            myDialog.title = title;
            myDialog.iconId = iconId;
            myDialog.context = context;
        }

        public MyDialog show() {
            MyDialog myDialog = new MyDialog(context);
            applyConfig(myDialog);
            return myDialog;
        }

    }
}
